package com.example.hm_dtfkz.config;

import com.android.base.util.DQLog;
import com.android.base.util.JsonUtil;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.app.QuestionsApp;
import com.example.hm_dtfkz.entity.AnswerEntity;
import com.example.hm_dtfkz.entity.HelpEntity;
import com.example.hm_dtfkz.entity.MeEntity;
import com.example.hm_dtfkz.litepal.AnswerLitePalEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * FileName: AppDataSourse
 * Author: admin
 * Date: 2021/11/4 16:50
 * Description:
 */
public class AppDataSourse {
    public static List<MeEntity> getSettingData1() {
        List<MeEntity> list = new ArrayList<>();
        list.add(new MeEntity(R.drawable.icon_fragment_me_item_privacy, "隐私政策", null));
        list.add(new MeEntity(R.drawable.icon_fragment_me_item_agreement, "用户协议", null));
        return list;
    }

    public static List<MeEntity> getSettingData2() {
        List<MeEntity> list = new ArrayList<>();
        list.add(new MeEntity(R.drawable.icon_fragment_me_item_help, "帮助中心", null));
        list.add(new MeEntity(R.drawable.icon_fragment_me_item_about, "关于我们", null));
        list.add(new MeEntity(R.drawable.icon_fragment_me_item_check, "检查更新", null));
        return list;
    }

    public static List<HelpEntity> getHelpData() {
        List<HelpEntity> list = new ArrayList<>();

        list.add(new HelpEntity(HelpEntity.TYPE_RECEIVE, null, new HelpEntity.SendEntity("如何注销账户?")));//问
        list.add(new HelpEntity(HelpEntity.TYPE_SEND, new HelpEntity.ReceiveEntity("首页——设置——注销账号，注销账号的同时，当前账户所有余额会被永久清除，绑定的微信无法再次绑定其他账号，且后续无法恢复，注销前请再三确认."), null));//答

        list.add(new HelpEntity(HelpEntity.TYPE_RECEIVE, null, new HelpEntity.SendEntity("一个微信可以绑定几次？")));//问
        list.add(new HelpEntity(HelpEntity.TYPE_SEND, new HelpEntity.ReceiveEntity("一个微信只能绑定一个账号，请绑定正确的微信账号保障奖品能够顺利发放."), null));//答

//        list.add(new HelpEntity(HelpEntity.TYPE_RECEIVE, null, new HelpEntity.SendEntity("如何查看答题进度？")));//问
//        list.add(new HelpEntity(HelpEntity.TYPE_SEND, new HelpEntity.ReceiveEntity("在首页小书童周围，可以看到您当前的总共答题数与答对数量."),null));//答

        list.add(new HelpEntity(HelpEntity.TYPE_RECEIVE, null, new HelpEntity.SendEntity("如何反馈？")));//问
        list.add(new HelpEntity(HelpEntity.TYPE_SEND, new HelpEntity.ReceiveEntity("您可以加入相关客服QQ群" + AppConfig.QQ_GROUP + "进行反馈，将您遇到的问题告知我们的客服."), null));//答

        return list;
    }

    public static Map<Integer, List<AnswerEntity.DataBean>> answerEntityList = null;

    public static List<AnswerEntity.DataBean> getAnswerData(AnswerLitePalEntity litePalEntity) {
        if (litePalEntity == null) {
            DQLog.e("litePalEntity == null");
            return null;
        }
        if (answerEntityList == null || !answerEntityList.containsKey(litePalEntity.getAnswerType())) {//如果本地答题文件读取失败
            String assetsData = AnswerDataConfig.getJson(litePalEntity.getAssetsName(), QuestionsApp.context);
            AnswerEntity entities = (AnswerEntity) JsonUtil.fromJson(assetsData, new AnswerEntity());
            answerEntityList = new HashMap<>();
            answerEntityList.put(litePalEntity.getAnswerType(), entities.getNewslist());
            setAnswerEntityList(answerEntityList);
        }
        List<AnswerEntity.DataBean> list = new ArrayList<>();
        if (litePalEntity.getAnswerRound() != 0) {
            for (int index = 0; index < litePalEntity.getAnswerRound(); index++) {
                DQLog.e("添加第" + index + "");
                list.addAll(0, answerEntityList.get(litePalEntity.getAnswerType()));
            }
        } else {
            list.addAll(answerEntityList.get(litePalEntity.getAnswerType()));
        }
        DQLog.e("题目一共" + litePalEntity.getAnswerRound() + "轮,每一轮" + list.size() + "道题目" + "，当前第" + litePalEntity.getAnswerPosition() + "道题");
        return list;
    }

    public static void setAnswerEntityList(Map<Integer, List<AnswerEntity.DataBean>> entityList) {
        AppDataSourse.answerEntityList = entityList;
    }
}
